<script type="text/javascript" src="js/jquery.idTabs.min.js"></script>
<script>
	$(function(){
		$("#tab").idTabs();
		$('.info .status-0').text('<?php echo Fund::status(0); ?>('+$('.list .status-0').size()+')');
		$('.info .status-1').text('<?php echo Fund::status(1); ?>('+$('.list .status-1').size()+')');
		$('.info .status-2').text('<?php echo Fund::status(2); ?>('+$('.list .status-2').size()+')');
		$('.info .status-3').text('<?php echo Fund::status(3); ?>('+$('.list .status-3').size()+')');

		$('[class^=status]').click(function(){
			var status = $(this).attr('class');
			if(status == 'status-all'){
				$('.list tbody tr').fadeIn();
			}else{
				$('.list tbody tr').hide();
				$('.list .'+status).parent().parent().fadeIn();
			}
		});
	});
</script>
<h1><?php echo $fund['name']; ?></h1>
<ul id="breadcrumb">
	<li><a href="#">การบันทึกบัญชีใบสำคัญรับเงินส่วนของพมจ.</a></li>		
	<li><?php echo month($month).' '.$year; ?></li>	
</ul>
<div id="content">
	<div class="search">
		<form aaction="dashboard/all/<?php echo $fund['id'].'/'.$year.'/'.$month; ?>" method="get">
			<label>ปีงบประมาณ</label> <?php echo form_dropdown('year', get_year_option('2550'), $year); ?>
			&nbsp;&nbsp;<label>เดือน</label> <?php echo form_dropdown('month', get_month(), $month); ?>
			<input type="submit" value="<?php echo lang('search'); ?>" class="button" />
		</form>
	</div>
	<ul id="tab" class="tab">
		<li><a href="#tab1">พมจ.</a></li>
		<li><a href="#tab2">บันทึกบัญชีใบสำคัญรับเงิน</a></li>
	</ul>
	
	<div id="tab1">
		<div class="info">
			<a href="javascript:;" class="status-all">พมจ. ทั้งหมด(<?php echo count($provinces);?>)</a>
			&nbsp;&nbsp;<a href="javascript:;" class="status-0"></a>
			&nbsp;&nbsp;<a href="javascript:;" class="status-1"></a>
			&nbsp;&nbsp;<a href="javascript:;" class="status-3"></a>
			&nbsp;&nbsp;<a href="javascript:;" class="status-2"></a>
		</div>
	<table class="list">
		<thead>
		<tr>
			<th>พมจ.</th>
			<th width="50">ล็อค</th>
			<th width="580"></th>
			<th width="180">สถานะ</th>
			<th width="140"></th>
		</tr>
		</thead>
		<tbody>
		<?php foreach($provinces as $key => $item): ?>
		<tr <?php echo cycle($key); ?>>
			<td><?php echo $item['agency_name']; ?></td>
			<td class="center">
				<?php echo anchor('setting/toggle/'.$fund['id'].'/'.$item['a_id'],img(Fund::is_agency_lock($fund['id'], $item['a_id']) ? 'themes/fund/images/icon/lock.gif' : 'themes/fund/images/icon/unlock.png'));?>
			</td>
			<td style="text-align:center;">
			<?php echo anchor('registration/index/'.$fund['id'].'/'.$year.'/'.$month.'/'.$item['a_id'], '<span class="icon_text table_money"></span>ทะเบียนคุมเงินกองทุน', 'class="button"'); ?>
			<?php echo anchor('income_expenses/view/'.$fund['id'].'/'.$year.'/'.$month.'/'.$item['a_id'], '<span class="icon_text coin"></span>รายงานการรับ-จ่ายเงิน', 'class="button"'); ?>
			<?php echo anchor('banking_balance/view/'.$fund['id'].'/'.$year.'/'.$month.'/'.$item['a_id'], '<span class="icon_text bank"></span>งบพิสูจน์ยอดเงินฝากธนาคาร', 'class="button"'); ?>
			</td>
			<td style="text-align:center;"><?php echo Fund::status($item['status'], TRUE); ?></td> 
			<td class="center">
				<?php if($item['status'] == 1): ?>
				<?php echo anchor('dashboard/change_status/'.$fund['id'].'/'.$item['a_id'].'/'.$year.'/'.$month.'/2', 'ผ่าน', 'class="button"'); ?>
				<?php echo anchor('dashboard/change_status/'.$fund['id'].'/'.$item['a_id'].'/'.$year.'/'.$month.'/3', 'ไม่ผ่าน', 'class="button"'); ?>
				<?php endif; ?>
			</td>
		</tr>
		<?php endforeach; ?>
		</tbody>
	</table>
	</div>
	
	<div id="tab2">
		<?php echo form_open('income_expenses/save/'.$fund['id'].'/'.$year.'/'.$month); ?>
		<table class="form">
			<tr><th>วันเดือนปีที่ลงบัญชี</th><td><input type="text" name="voucher_date" value="<?php echo mysql_to_date($rs['voucher_date'], TRUE); ?>" class="datepicker" readonly="readonly" rel="<?php echo date('d').'/'.$month.'/'.$year; ?>" /></td></tr>
			<tr><th>เลขที่</th><td><input type="text" name="number" value="<?php echo $rs['number']; ?>" /></td></tr>
		</table>
	<table class="tbform">
		
		<tr>
			<th>ชื่อบัญชี</th>
			<th width="100">หน้าบัญชี</th>
			<th width="100">เดบิต</th>
			<th width="100">เครดิต</th>
		</tr>
		
		<?php foreach($vouchers as $key => $item): ?>
		
		<?php if(!empty($voucher_total[1]) && $key == 0): ?>
		<tr>
			<td class="dr1">เงินโอนให้หน่วยงาน</td>
			<td></td>
			<td class="number">
				<?php $price = (!empty($voucher_total[1])) ? $voucher_total[1] : NULL; echo number_format($price, 2); ?>
				<?php echo form_hidden('price[1][59]', $price); ?>
				<?php echo form_hidden('type[1][59]', 'dr'); ?>
				
			</td>
			<td></td>
		</tr>
		<?php endif; ?>
				
		<tr>
			<?php $class = ($item['side'] == 1 ) ? 'cr' : 'dr'; ?>
			
			<?php $price = (!empty($item['total_price'])) ? $item['total_price'] : NULL; ?>
			<?php echo form_hidden('price['.$item['side'].']['.$item['account_id'].']', $price); ?>
			<?php echo form_hidden('type['.$item['side'].']['.$item['account_id'].']', $class); ?>
			
			
			<td class="<?php echo $class; ?>1"><?php echo $item['col_title']; ?></td>
			<td></td>
			<?php if($class == 'dr'): ?>
				<td class="number"><?php echo number_format($price, 2); ?></td>
				<td></td>
			<?php else: ?>
				<td></td>
				<td class="number"><?php echo number_format($price, 2); ?></td>
			<?php endif; ?>
		</tr>
		
		<?php if(!empty($voucher_total[2]) && $key == array_pop(array_keys($vouchers))): ?>
		<tr>
			<td class="cr1">เงินโอนให้หน่วยงาน</td>
			<td></td>
			<td></td>
			<td class="number">
				<?php $price = (!empty($voucher_total[2])) ? $voucher_total[2] : NULL; echo number_format($price, 2); ?>
				<?php echo form_hidden('price[2][59]', $price); ?>
				<?php echo form_hidden('type[2][59]', 'cr'); ?>
				
			</td>
		</tr>
		<?php endif; ?>
		
		<?php endforeach; ?>
	</table>
	<table class="form">
		<tr><th>คำอธิบาย</th><td><textarea name="description" cols="100" rows="6" ><?php echo $rs['description'] ?></textarea></td></tr>
	</table>
	<?php echo form_submit('', lang('btn_submit')); ?>
	<?php echo form_hidden('fund_id', $fund['id']); ?>
	<?php echo form_hidden('year', $year); ?>
	<?php echo form_hidden('month', $month); ?>
	<?php echo form_close(); ?>
	</div>

</div>